package design.Prototype;

import java.util.ArrayList;

/**
 * Created by looper on 2017/8/15.
 */
//1.继承Cloneable接口
public class Prototype implements Cloneable {

  private ArrayList list = new ArrayList<>();

  //但是有一个问题,习惯性的经常使用List接口来代替ArrayList
//  private List list = new ArrayList<>();

  //2.重写Object类的clone方法.
  public Object clone() throws CloneNotSupportedException {
    Prototype prototype = (Prototype) super.clone();

    //将不是基本数据类型的另行拷贝,(当使用List代替ArrayList时,没有clone方法)
    prototype.list = (ArrayList)this.list.clone();
    return prototype;
  }
}
